package com.autumn.zero.workflow.application.dto.forms;

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.autumn.common.api.application.dto.DefaultEntityDto;
import com.autumn.common.api.constants.SimpleDataTypeConstant;
import com.autumn.util.ExceptionUtils;
import com.autumn.validation.annotation.NotNullOrBlank;
import com.autumn.zero.workflow.entitys.WorkflowFormProperty;

/**
 * 工作流表单属性输入
 * 
 * @author 杨昌国 2018-12-20 10:00:35
 */
public class WorkflowFormPropertyInput extends DefaultEntityDto {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6114878302461770140L;

	/**
	 * 属性名称
	 */
	@NotNullOrBlank(message = "属性不能为空")
	@Length(max = WorkflowFormProperty.MAX_PROPERTY_NAME_LENGTH, message = "属性不能为空长度不能超过"
			+ WorkflowFormProperty.MAX_PROPERTY_NAME_LENGTH + "个字。")
	private String propertyName;

	/**
	 * 友好名称
	 */
	@NotNullOrBlank(message = "属性友好名称不能为空")
	@Length(max = WorkflowFormProperty.MAX_FRIENDLY_NAME_LENGTH, message = "属性友好名称不能为空长度不能超过"
			+ WorkflowFormProperty.MAX_FRIENDLY_NAME_LENGTH + "个字。")
	private String friendlyName;

	/**
	 * 属性类型 {@link com.autumn.common.api.constants.SimpleDataTypeConstant}
	 */
	@NotNull(message = "属性类型不能为空")
	private Integer propertyType;

	/**
	 * 获取属性名称
	 * 
	 * @return
	 */
	public String getPropertyName() {
		return propertyName;
	}

	/**
	 * 设置属性名称
	 * 
	 * @param propertyName 属性名称
	 */
	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	/**
	 * 获取友好名称
	 * 
	 * @return
	 */
	public String getFriendlyName() {
		return friendlyName;
	}

	/**
	 * 设置友好名称
	 * 
	 * @param friendlyName 友好名称
	 */
	public void setFriendlyName(String friendlyName) {
		this.friendlyName = friendlyName;
	}

	/**
	 * 获取属性类型
	 * 
	 * @return {@link com.autumn.common.api.constants.SimpleDataTypeConstant}
	 */
	public Integer getPropertyType() {
		return propertyType;
	}

	/**
	 * 设置属性类型
	 * 
	 * @param propertyType 属性类型
	 *                     {@link com.autumn.common.api.constants.SimpleDataTypeConstant}
	 */
	public void setPropertyType(Integer propertyType) {
		this.propertyType = propertyType;
	}

	@Override
	public void valid() {
		super.valid();
		if (!SimpleDataTypeConstant.exist(this.getPropertyType())) {
			ExceptionUtils.throwValidationException("指定的属性数据类型无效。");
		}
	}

}
